<?php
/* Used to Test LDAP*/
// basic sequence with LDAP is connect, bind, search, interpret search
// result, close connection
require_once('config.inc.php');
$ds=ldap_connect(LDAP_SERVER);
if ($ds) { 
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    if (!ldap_set_option($ds, LDAP_OPT_REFERRALS, 0)) { 
    exit('Failed to set opt referrals to 0'); 
} 
    echo "Binding ..."; 
    $r=ldap_bind($ds,"join","join");     

    echo "Bind result is " . $r . "<br />";

    echo "Searching for (sn=glosappio) ...";
    $cn = "samaccountname=glosappio";
    // Search surname entry
    $sr=ldap_search($ds, $dn , $cn); 
    
    echo "Search result is " . $sr . "<br />";

    echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "<br />";

    echo "Getting entries ...<p>";
    $info = ldap_get_entries($ds, $sr);
    echo "Data for " . $info["count"] . " items returned:<p>";

    for ($i=0; $i<$info["count"]; $i++) {
        echo "dn is: " . $info[$i]["dn"] . "<br />";
        echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
     
    }

    echo "Closing connection";
    ldap_close($ds);

} else {
    echo "<h4>Unable to connect to LDAP server</h4>";
}
?>